#coding:utf-8
#! ‪C:\Developer\python36\python3.exe

'''
[[40.918526957150952, 24.89442133466094]]
'''
# from go import getPos
# path = r'imgs/151028460.gif'
# print(getPos(path))
# if 'a' not in 'abb':
#     print(123)

# a = 'abcde'
# b = 'abcdefghij'
# str
# c = b-a
# print(c)
import lxml
import  lxml.etree
htmlFile = open('html.txt','r',encoding='utf-8')
html = htmlFile.read()
htmlFile.close()

myTree = lxml.etree.HTML(html)
# divList = myTree.xpath('//div[@class="TopstoryMain"]/div//div')
divList = myTree.xpath('//div[@class="TopstoryMain"]/div/div')
# title = div.xpath('./div[1]/div[2]/h2/div/a/text()')[0]
for div in divList:
    title = div.xpath('.//a[@data-za-detail-view-element_name="Title"]/text()')
    man = div.xpath('./div[1]/div[2]/div/div/div/div/div/span/div/div/a/text()')
    answerList = div.xpath('./div[1]/div[2]/div[2]/div[2]/span//p')
    times = div.xpath('./div[1]/div[2]/div[2]/div[3]/div/a/span/@data-tooltip')
    if len(answerList) ==0:
        break
    if len(title):
        print(title)
    else:
        break

    if len(man):
        print(man[0])


    for p in answerList:
        answer = p.xpath('./text()')
        if len(answer)!=0:
            print(answer[0])
        else:
            break

    if len(times):
        print(times)
# file = open('zhihu.txt','w')
# for div in divList:
#     title = div.xpath('./div[1]/div[2]/h2/div/a/text()')[0]
#     file.write(title)
#     print(title)
#     man = div.xpath('./div[1]/div[2]/div/div/div/div/div/span/div/div/a/text()')[0]
#     file.write(man)
#     answerList =div.xpath('./div[1]/div[2]/div[2]/div[2]/span//p')
#     answer = []
#     for p in answerList:
#         answer = p.xpath('./text()')[0]
#         file.write(answer)
#     times = div.xpath('./div[1]/div[2]/div[2]/div[3]/div/a/span/@data-tooltip')[0]
#     file.write(times)
#
# file.close()
#
#
#
